﻿using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TipPanel : MonoBehaviour
{
    public static TipPanel Instance;

    public List<string> list;

    float timer;
    float timerCount;

    private void Awake()
    {
        Instance = this;
        list = new List<string>();

        timerCount = timer = 2f;
    }

    private void Update()
    {
        timerCount += Time.deltaTime;
        if (timerCount >= timer)
        {
            timerCount = 0;
            if (list.Count > 0)
            {
                Show(list[0]);
                list.RemoveAt(0);
            }
        }
    }

    //外部调用
    public void Open(string content)
    {
        if (list.Count == 0)
        {
            timerCount = timer;
        }
        list.Add(content);
    }

    public void Show(string content)
    {
        Transform child = ShuaiFunctions.GetFreeChild(this.transform);
        child.gameObject.SetActive(true);
        child.transform.localPosition = Vector3.zero;
        Text Text_current = child.GetComponent<Text>();
        Text_current.text = content;

        Tween tweener = child.DOMoveY(child.position.y + 300, 1.4f);
        tweener.SetEase(Ease.Flash);
        tweener.onComplete = () =>
        {
            child.gameObject.SetActive(false);
        };
    }
}
